define(function() {
	return function($compile, $scope) {
		require([ "AppPathDir/order/receivedAusoInfos/support", "AppPathDir/order/receivedAusoInfos/detail", "AppPathDir/order/receivedAusoInfos/refund", "PDUtilDir/util",
				"PDUtilDir/tool", "PDUtilDir/inputSelect", "Date", "DateCN",
				"css!DateCss"], function(Support, DetailSupport, RefundSupport, Util, Tool, inputSelect) {
			$scope.search = {};
			$scope.cache = {
                payPlatformMap: new Map(),
                payPlatforms: new Array(),
				payStatusMap: new Map(),
				payStatus: new Array(),
				statusMap: new Map(),
				status: new Array(),
                applyTypeMap: new Map(),
                applyTypes: new Array(),
				images: new Array()
			};
			/* 查询 */
			$scope.searchSupport = {
				run : function() {
					$scope.grid.reload({
						queryParam : {
							model : JSON.stringify($scope.search.orderNo)
						}
					})
				}
			};
			/* 同意 */
			$scope.agree = {
				run : function(id) {
					Util.confirm("是否确认", function() {
						$.ajax({
							url : getServer() + "/flea/hclv/serviceOrder/agreeServiceOrderUpdateApply.htmls",
							data: {
								model: id
							},
							success : function(data) {
								$scope.grid.refresh();
							}
						});
					})
				}
			};
			/* 否定 */
			$scope.veto = {
				run : function(id) {
					Util.confirm("是否确认", function() {
						$.ajax({
							url : getServer() + "/flea/hclv/serviceOrder/rejectServiceOrderUpdateApply.htmls",
							data: {
								model: id
							},
							success : function(data) {
								$scope.grid.refresh();
							}
						});
					})
				}
			};
			// 状态
			$.ajax({
				url : getServer() + "/flea/hclv/getUpdateSerivcOrderUpdateApplyStatus.htmls",
				success : function(data) {
					$scope.cache.status = data.data;
					$.each(data.data, function(index, row) {
						$scope.cache.statusMap.set(row.dictCode, row.dictName);
					});
					// 初始化下拉框
					inputSelect.dropCache();
					inputSelect({
						id : "orderStatus",
						key : {
							id : "dictCode",
							name : "dictName",
							data : "data",
						},
						data : $scope.cache.status,
						simpleData : true,
						searchAble : false,
						callback : function(id) {
							var id = id[0];
							$scope.search.orderStatus = id;
						}
					});
					$scope.renderGridFun();
				}
			});
            // 支付类型
            $.ajax({
                url : getServer() + "/flea/hclv/getPayType.htmls",
                success : function(data) {
                    $scope.cache.payPlatforms = data.data;
                    $.each(data.data, function(index, row) {
                        $scope.cache.payPlatformMap.set(row.dictCode, row.dictName);
                    });
                }
            });
            $scope.refundSupport = new RefundSupport($scope, $compile);
            /* 申請类型 */
            $.ajax({
                url : getServer() + "/flea/hclv/getServiceApplyType.htmls",
                success : function(data) {
                    $scope.cache.applyTypes = data.data;
                    $.each(data.data, function(index, row) {
                        $scope.cache.applyTypeMap.set(row.dictCode, row.dictName);
                    });
                    $scope.renderGridFun();
                }
            });

			$scope.detailSupport = DetailSupport($scope, $compile);
			$scope.renderGridFun = function(){
				if($scope.cache.applyTypes.length > 0 && $scope.cache.status.length > 0)
				$scope.grid = Support.init($scope.cache, $scope.searchSupport, $scope.detailSupport);
			}
		})
	}
});